home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / assign manager / assignx / assignx.c < prev    next >
C/C++ Source or Header  |  1996-04-07  |  3KB  |  139 lines

  1. /************************************************************************/
  2. /*  EasyRequest trapper - deals with requests for nonexistant volumes   */
  3. /*                        V1.1, by Steve Tibbett                        */
  4. /************************************************************************/
  5. #include <Stdio.h>
  6. #include <libraries/gadtools.h>
  7. #include <intuition/intuition.h>
  8. #include <proto/gadtools.h>
  9. #include <proto/asl.h>
  10. #include <proto/exec.h>
  11. #include <proto/dos.h>
  12. #include <dos/dos.h>
  13. #include <exec/memory.h>
  14. #include <string.h>
  15. #include <ctype.h>
  16.  
  17. struct Library *IntuitionBase;
  18. struct Library *AslBase;
  19. struct Remember *Remember;
  20.  
  21. void MemCleanup(void) { }
  22.  
  23. struct AbortedList
  24.     {
  25.     struct AbortedList *Next;
  26.     char Name[1];
  27.     } *AbortedList;
  28.  
  29. void *OrigFunc;
  30.  
  31. char AXVersion[] = "$VER: AssignX 1.2 (22-Apr-91) by Steve Tibbett";
  32.  
  33. /************************************************************************/
  34. /*                        The new "EasyRequest"                         */
  35. /************************************************************************/
  36. int __saveds __interrupt __asm
  37. NewFunc(register __a0 struct Window *Win, register __a1 struct EasyStruct *EZ,
  38. register __a2 ULONG *idcmp, register __a3 ULONG *args)
  39. {
  40. int Res;
  41. int Mine=0;
  42.  
  43. if (EZ->es_TextFormat[0]=='%' && EZ->es_TextFormat[1]=='s' && args && args[0] && (strcmp((char *)args[0], "Please insert volume")==0))
  44.     {
  45.     struct AbortedList *AL=AbortedList;
  46.  
  47.     while (AL)
  48.         {
  49.         if (stricmp((char *)AL->Name, (char *)args[1])==0)
  50.             return(0);
  51.  
  52.         AL=AL->Next;
  53.         };
  54.  
  55.     EZ->es_GadgetFormat="Retry|Assign...|Mount|Deny|Cancel";
  56.     Mine=1;
  57.     };
  58.  
  59. Res=MyFunc(Win, EZ, idcmp, args);
  60.  
  61. if (Mine)
  62.     {
  63.     switch (Res)
  64.         {
  65.         case 2:
  66.             {
  67.             BPTR AsnLock;
  68.             char buff[80];
  69.             char *FullName;
  70.             struct FileRequester *FR;
  71.  
  72.             strcpy(buff, "Assignment for '");
  73.             strcat(buff, (char *)args[1]);
  74.             strcat(buff, "':");
  75.  
  76.             FR=(struct FileRequester *)AslFileRequest(Win, buff, "RAM:", "", 0, &FullName);
  77.             if (FR) {
  78.                 AsnLock=Lock(FullName, ACCESS_READ);
  79.                 if (AsnLock)
  80.                     AssignLock((char *)args[1], AsnLock);
  81.  
  82.                 FreeVec(FullName);
  83.                 FreeFileRequest(FR);
  84.                 };
  85.             return(1);
  86.             break;
  87.             };
  88.         case 3:
  89.             {
  90.             char buff[128];
  91.             strcpy(buff, "Mount >NIL: <NIL: ");
  92.             strcat(buff, args[1]);
  93.             strcat(buff, ":");
  94.             System(buff,0);
  95.             return(1);
  96.             };
  97.  
  98.         case 4:
  99.             {
  100.             struct AbortedList *AL=(struct AbortedList *)AllocRemember(&Remember, strlen((char *)args[1])+sizeof(struct AbortedList)+2, MEMF_CLEAR);
  101.             if (AL) {
  102.                 strcpy(AL->Name, (char *)args[1]);
  103.                 AL->Next=AbortedList;
  104.                 AbortedList=AL;
  105.                 };
  106.             };
  107.         };
  108.     };
  109.  
  110. return(Res);
  111. }
  112.  
  113.  
  114. main()
  115. {
  116. void *OurVec;
  117.  
  118. IntuitionBase=OpenLibrary("intuition.library", 36);
  119. AslBase=OpenLibrary("asl.library", 36);
  120. if (IntuitionBase==0 || AslBase==0)
  121.     return(10);
  122.  
  123. OrigFunc=SetFunction(IntuitionBase, -0x24c, NewFunc);
  124. if (OrigFunc==0)
  125.     return(15);
  126.  
  127. Wait(SIGBREAKF_CTRL_C);
  128.  
  129. OurVec=SetFunction(IntuitionBase, -0x24c, OrigFunc);
  130.  
  131. if (OurVec!=NewFunc)
  132.     EasyRequester(NULL, "AssignX Request", "Error removing wedge!\nReboot soon!", "Okay");
  133.  
  134. FreeRemember(&Remember, TRUE);
  135. CloseLibrary(IntuitionBase);
  136. CloseLibrary(AslBase);
  137. return(0);
  138. }
  139.